package com.own.component.elastic.entity;

import com.own.component.common.base.entity.po.BaseBean;
import com.own.component.elastic.core.advanced.aop.ElasticFieldZonedDateTime;
import com.own.component.elastic.core.advanced.aop.ElasticId;
import com.own.component.util.time.ZonedDateTimeUtil;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;
import lombok.experimental.FieldNameConstants;

import java.io.Serializable;
import java.time.ZonedDateTime;

/**
 * BaseElasticPo
 *
 * @author chenxueli
 * @date 2021-08-27 10:27:00
 */
@Schema(title = "es搜索引擎对象")
@Getter
@Setter
@Accessors(chain = true)
@ToString
@NoArgsConstructor
@AllArgsConstructor
@FieldNameConstants
public class BaseElasticPo<T extends BaseBean> implements Serializable {

    @ElasticId(name = "主键id")
    private String id;

    @ElasticFieldZonedDateTime(name = "创建时间")
    private ZonedDateTime gmtCreate;

    /**
     * 根据po对象构建es的po对象
     *
     * @param po po对象
     */
    public BaseElasticPo(T po) {
        this.id = po.getId() + "";
        this.gmtCreate = ZonedDateTimeUtil.of(po.getGmtCreate());
    }

}
